### BEGIN INIT INFO
# Provides:          zram
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Use compressed RAM as in-memory swap
# Description:       Use compressed RAM as in-memory swap
### END INIT INFO

### Esse Script foi inspiado no zram do Arch Linux e adaptado para o PCLinuxOS.

MEM=$(perl -ne '/^MemTotal:\s+(\d+)/ && print $1*1024' < /proc/meminfo)

case "$1" in
    start)
        modprobe zram
        echo lz4 > /sys/block/zram0/comp_algorithm
	echo $MEM > /sys/block/zram0/disksize
        mkswap --label zram0 /dev/zram0
        swapon --priority 100 /dev/zram0
        
	;;
    stop)
        swapoff /dev/zram0
        wait
        sleep .5
        rmmod zram
        ;;
    *)
        echo "Usage: $(basename $0) (start | stop)"
        exit 1
        ;;
esac

# End of file

